module encode83(x, en, y, valid);
  input [7:0] x;
  input en;
  output reg [2:0] y;
  output reg valid;
  integer i;

  always @(x or en)
  begin
    if (en)
    begin
      y = 0;
      for (i = 0; i <= 7; i = i + 1)
        if (x[i] == 1) y = i[2:0];
    end
    else y = 0;

    if (x == 0)
      valid = 1'b0;
    else
      valid = 1'b1;
  end

endmodule
